// Learn TypeScript:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/typescript.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    

    items:LevelDataItem[] = [];

    item:LevelDataItem;

    levelDataArray=[];
    // LIFE-CYCLE CALLBACKS:

    onLoad () {

        function  Levelitem(answer,img,word,tip,content) //声明对象
        {
          this.Answer=answer;

          this.Imag=img;
          this.Word=word;
          this.Tip=tip;
          this.Content=content;
          
        }
        
         //使用RES读取和构建JSON数据，JSON数据可以直接解析到目标结构
         cc.loader.loadRes('test assets/question' ,function(err,res){
            if (err) {
                cc.log("+++++++++++++++++++++++++"+err);
                }
            else{
                var list = res;

                var levelArray=[];

                console.log("list 0 ："+list[0].answer);

                for(let i=0;i<list.length;i++)
                {
                   levelArray.push(new Levelitem(list[i].answer,list[i].img,list[i].word,list[i].tip,list[i].content));
                }
                
                console.log("LevelArray的个数："+levelArray.length);

               // this.levelDataArray=levelArray;

               // console.log("LevelDataArray的个数："+this.levelDataArray.length);

               // LevelDataItem item=new LevelDataItem();

               function  ObjStory(id,biaoti,author,type) //声明对象
               {
                  this.ID = id;
                  this.Biaoti= biaoti;
                  this.Author= author;
                  this.Type = type;
                 
               }
               var Array=[];
          
               Array.push(new ObjStory(12,'大家去看海','李大胆','文艺类'));
               
               Array.push(new ObjStory(15,'大家去dsfas看海','李df大胆','文艺类a'));

               Array.push(new ObjStory(15,'大家去看海','李大胆','文艺类'));

               Array.push(new ObjStory(15,'大家去看海','李大胆','文艺类'));

               Array.push(new ObjStory(15,'大家去看海','李大胆','文艺类'));
               console.log("Array的个数："+Array.length);

          var arr =[];//声明数组，用来存储标题信息
          
           var writer= new ObjStory(15,'大家去看海','李大胆','文艺类');//声明对象
           arr[0]=writer;//向集合中添加对象
          //另一种方法：
    
            };
        });   
    }

    
    // update (dt) {}
}


//每个问题（关卡）的数据结构
class LevelDataItem{
    public answer:string;
    public img:string;
    public word:string;
    public tip:string;
    public content:string;
}